package com.sds.session.manager;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.Cookie;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sds.session.manager.vo.UserInfo;

public class SessionMasterInfo {
	private Logger logger = LoggerFactory.getLogger(SessionMasterInfo.class);
	private Map<String, UserInfo> userInfos = new HashMap<String, UserInfo>();

	public UserInfo getUserInfo(String userId, String userIP) {
		return userInfos.get(userId+"|"+userIP);
	}
	
	public void setUserInfo(String userId, String userIP, Cookie[] cookie, String domain) {
		UserInfo userInfo = getUserInfo(userId, userIP);
		if(userInfo==null) {
			userInfo = new UserInfo(userId, userIP, domain, cookie);
			userInfos.put(userId+"|"+userIP, userInfo);
		} else {
			userInfo.addDomain(domain, cookie);
		}
		
		if( logger.isDebugEnabled() ) {
			logger.debug("=================== User Info =====================");
			for( Object key : userInfos.keySet().toArray() ) {
				userInfos.get(key).debug();
			}
			logger.debug("===================================================");
		}
	}
}
